home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / haziran / 19 / setup.exe / data.z / int_lib.bas < prev    next >
BASIC Source File  |  2001-04-11  |  3KB  |  103 lines

  1. Attribute VB_Name = "int_lib"
  2. '
  3. ' File - int_lib.bas
  4. '
  5. ' This application catches interrupts that are genereted by the
  6. ' computer components, and is controlled via a graphical user
  7. ' interface - int_gui.frm
  8. ' The interrupts are detected using WinDriver functions.
  9. '
  10.  
  11. Option Explicit
  12. Private g_cardReg As WD_CARD_REGISTER
  13. Private g_phThread As Long
  14. Global g_intrp As WD_INTERRUPT
  15.         
  16. Sub Int_Handler(ByVal pData As Long)
  17.     int_gui.IntCount = g_intrp.dwCounter
  18.     int_gui.IntCount.Refresh
  19. End Sub
  20.  
  21. Function Interrupt_Thread_Enable(hWD As Long, intrp As WD_INTERRUPT, CurIrq As Integer) As Boolean
  22.     g_phThread = 0
  23.     g_cardReg.Card.dwItems = 1
  24.     g_cardReg.Card.Item(0).Item = ITEM_INTERRUPT
  25.     g_cardReg.Card.Item(0).fNotSharable = False
  26.     g_cardReg.Card.Item(0).dw1 = CurIrq
  27.     g_cardReg.Card.Item(0).dw2 = 0
  28.     g_cardReg.fCheckLockOnly = False
  29.     WD_CardRegister hWD, g_cardReg
  30.     If (g_cardReg.hCard = 0) Then
  31.         MsgBox "Failed locking device", vbCritical + vbOKOnly, "Interrupt listener"
  32.         GoTo Error
  33.     Else
  34.         intrp.hInterrupt = g_cardReg.Card.Item(0).dw3
  35.         intrp.dwCmds = 0
  36.         intrp.dwOptions = 0
  37.     End If
  38.  
  39.     If (InterruptThreadEnable(g_phThread, hWD, intrp, _
  40.         AddressOf Int_Handler, 0, int_gui.hWnd) = 0) Then
  41.         MsgBox "Failed enabling interrupt. Interrupt already in use", vbCritical + vbOKOnly, "Interrupt listener"
  42.         GoTo Error
  43.     End If
  44.     
  45.     ' Thread was created succesfuly
  46.     Interrupt_Thread_Enable = True
  47.     GoTo finish
  48.     
  49. Error:
  50.     ' Error during open
  51.     If (g_cardReg.hCard <> 0) Then
  52.         WD_CardUnregister hWD, g_cardReg
  53.     End If
  54.     Interrupt_Thread_Enable = False
  55.  
  56. finish:
  57. End Function
  58.  
  59. Sub Interrupt_Thread_Disable(hWD As Long)
  60.     If (g_phThread <> 0) Then
  61.         InterruptThreadDisable g_phThread
  62.     End If
  63.     If (g_cardReg.hCard <> 0) Then
  64.         WD_CardUnregister hWD, g_cardReg
  65.     End If
  66. End Sub
  67.  
  68. Function Int_Open(hWD As Long) As Boolean
  69.     Dim verBuf As WD_Version
  70.     
  71.     hWD = WD_Open()
  72.     If (hWD = INVALID_HANDLE_VALUE) Then
  73.         MsgBox "ERROR opening WinDriver", vbCritical + vbOKOnly, "Interrupt listener"
  74.         GoTo Error
  75.     End If
  76.         
  77.     WD_Version hWD, verBuf
  78.     If (verBuf.dwVer < WD_VER) Then
  79.         MsgBox "ERROR incorrect WinDriver version. needs ver " & WD_VER & Chr$(13) _
  80.         & "You are using WINDRVR version " & verBuf.dwVer, vbOKOnly, "Error"
  81.         GoTo Error
  82.     End If
  83.     
  84.     ' Open finished OK
  85.     Int_Open = True
  86.     GoTo finish
  87.     
  88. Error:
  89.    ' Error during open
  90.    If (hWD <> INVALID_HANDLE_VALUE) Then
  91.       WD_Close hWD
  92.    End If
  93.    Int_Open = False
  94.  
  95. finish:
  96. End Function
  97.  
  98. Sub Int_Close(hWD As Long)
  99.     If (hWD <> INVALID_HANDLE_VALUE) Then
  100.         WD_Close (hWD)
  101.     End If
  102. End Sub
  103.